package com.proxy.autoclick.checker.service;

import org.apache.http.client.HttpClient;

import com.proxy.autoclick.checker.dao.ProxyDao;
import com.proxy.autoclick.checker.http.proxy.ClientExecuteProxy;
import com.proxy.autoclick.checker.http.proxy.ClientExecuteProxyCheckGoogleHost;
import com.proxy.autoclick.common.valueobject.Proxy;

/**
 * Check proxy valid class.
 * @author paul
 *
 */
public class ProxyService {
	
	private ProxyDao proxyDao = new ProxyDao();
	
	/**
	 * check proxy if it is a valid for google, save to google_proxies table 
	 * check proxy if it is a valid for other, save to working_proxies table
	 * if it is valid for both, save to  both_proxies table
	 * update is_checked=b'1' to proxies table
	 * @param myProxy
	 * @throws Exception
	 */
	public void checkProxy(HttpClient httpclient,Proxy myProxy) throws Exception
	{
        
		ClientExecuteProxy clientExecuteProxyGoogle = new ClientExecuteProxyCheckGoogleHost(httpclient,myProxy);
		clientExecuteProxyGoogle.execue();
		
		proxyDao.deleteProxyIfInvalid(myProxy);
		
		/*if(myProxy.isValidForGoogleHost())
		{
			proxyDao.createOrUpdateGoogleProxies(myProxy);
		}
		
		ClientExecuteProxy clientExecuteProxyOther = new ClientExecuteProxyCheckOtherHost(httpclient,myProxy);
		clientExecuteProxyOther.execue();
		if(myProxy.isValidForOtherHost())
		{
			proxyDao.createOrUpdateOtherProxies(myProxy);
		}
		
		if(myProxy.isValidForGoogleHost() && myProxy.isValidForOtherHost())
		{
			proxyDao.createOrUpdateBothProxies(myProxy);
		}*/
		
	}
}
